<?php

namespace App\Console\Commands\customer;

use App\model\customer\Customer;
use App\model\customer\CustomerMobile;
use Illuminate\Console\Command;

class CustomerMobileCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'customer:mobile';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '将手机号转为多表储存';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $customer=Customer::all();
        foreach($customer as $item){
             /**
              * @var Customer $item
               */
           $customerMobile=   CustomerMobile::whereMobile($item->telephone)->whereCustomerId($item->customer_id)->first();
           if(!$customerMobile){
               $customerMobile=new CustomerMobile();
               $customerMobile->mobile= $item->telephone;
               $customerMobile->customer_id=$item->customer_id;
               $customerMobile->save();
               $this->info($customerMobile->id);
           }
        }
    }
}
